/* ====================================================================
 * (#)Header: LoggerInterceptor.java
 * (#)Revision: 
 * (#)Date Created: 2009-05-28
 * (#)Created By: Karol Wozniak
 * ====================================================================
 *
 * Copyright (c) 2007 karolak .  All rights reserved.
 *
 * ====================================================================
 * 
 * The software application represented here is the sole property of 
 * karolak. Its unauthorized utilization is expressly prohibited.
 * 
 * ====================================================================
 */
package com.karolak.service.ejb.interceptor;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * <code>LoggerInterceptor</code> is ....
 * 
 * @author <a href="mailto:kwozniak@hotmail.com">Karol Wozniak</a>
 */
public class LogInterceptor {

	protected final Log log = LogFactory.getLog(getClass());

	@AroundInvoke
	public Object log(InvocationContext inv) throws Exception {
		Object result = null;
		logBefore(inv);
		result = inv.proceed();
		logAfter(inv, result);
		return result;
	}

	protected void logBefore(InvocationContext inv) {
		if (log.isTraceEnabled()) {
			log.trace(InterceptorUtils.getMessageBeforeInvokation(inv));
		}
	}

	protected void logAfter(InvocationContext inv, Object result) {
		if (log.isTraceEnabled()) {
			log.trace(InterceptorUtils.getMessageAfterInvokation(inv, result));
		}
	}
}
